/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Autogenerated file -- DO NOT EDIT!

#ifndef LIBABCKIT_SRC_CODEGEN_INSN_BITSIZE_GETTER_H
#define LIBABCKIT_SRC_CODEGEN_INSN_BITSIZE_GETTER_H

#include <cstdint>

#include "compiler/optimizer/ir/runtime_interface.h"
#include "libabckit/include/c/isa/isa_dynamic.h"

% def GetBitImmSize(imm)
%   if (imm.eql? "IMM4")
%       return "AbckitBitImmSize::BITSIZE_4";
%   elsif (imm.eql? "IMM8")
%       return "AbckitBitImmSize::BITSIZE_8";
%   elsif (imm.eql? "IMM16")
%       return "AbckitBitImmSize::BITSIZE_16";
%   elsif (imm.eql? "IMM32")
%       return "AbckitBitImmSize::BITSIZE_32";
%   elsif (imm.eql? "IMM64")
%       return "AbckitBitImmSize::BITSIZE_64";
%   end
%   return "AbckitBitImmSize::BITSIZE_0";
% end

namespace libabckit {
    // NOLINTNEXTLINE(readability-function-size)
    inline AbckitBitImmSize GetIntrinsicBitImmSize(ark::compiler::RuntimeInterface::IntrinsicId intrinsicId, size_t idx = 0)
    {
        switch (intrinsicId)
        {
% Panda::instructions.select{|b| b.namespace == "ecmascript"}.each do |inst|
%   instFormat = inst.format.pretty.upcase.gsub("PREF_", "")
%   imms = instFormat.scan(/IMM\d+/)
%   if (imms.empty?)
%       next
%   end
            case ark::compiler::RuntimeInterface::IntrinsicId::DYN_<%= inst.opcode.upcase %>:
%       imms.each_with_index do |imm, idx|
                if (idx == <%= idx %>) {
                    return <%= GetBitImmSize(imm) %>;
                }
%       end
                break;
% end
            default:
                LIBABCKIT_LOG(DEBUG) << "imm not found" << '\n';
        }
        return AbckitBitImmSize::BITSIZE_0;
    }
} // namespace libabckit

#endif   //LIBABCKIT_SRC_CODEGEN_INSN_BITSIZE_GETTER_H